package com.lingnan.controller;

import com.lingnan.entity.vo.ChatSessionVO;
import com.lingnan.entity.vo.Result;
import com.lingnan.service.ChatSessionService;
import lombok.RequiredArgsConstructor;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chat/sessions")
@RequiredArgsConstructor
public class ChatSessionController {

    private final ChatSessionService sessionService;

    /**
     * 获取用户会话列表
     */
    @PostMapping
    public Result<List<ChatSessionVO>> getSessions(
            @RequestParam("userId") Long userId,
            @RequestParam("userType") Integer userType) {
        return Result.ok(
                sessionService.getUserSessionsVO(userId, userType)
        );
    }

    /**
     * 获取会话未读数（单个会话）
     * 修改点：明确指定@PathVariable名称
     */
    @GetMapping("/{sessionId}/unread")
    public Result<Integer> getSessionUnreadCount(
            @RequestParam("userId") Long userId,
            @PathVariable("sessionId") String sessionId) { // 关键修改
        return Result.ok(
                sessionService.getSessionUnreadCount(Long.valueOf(sessionId), userId)
        );
    }

    /**
     * 重置会话未读数
     * 修改点：明确指定@PathVariable名称
     */
    @PostMapping("/{sessionId}/reset-unread")
    public Result<Void> resetUnreadCount(
            @RequestParam("userId") Long userId,
            @PathVariable("sessionId") String sessionId) { // 关键修改
        sessionService.resetUnreadCount(Long.valueOf(sessionId), userId);
        return Result.ok();
    }
}